package StudyCode.summary.myfile;

import java.io.File;
import java.io.IOException;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateTempFile {

	public static void main(String[] args) {
		File file = generateTempFile("112", "txt");
		if (file != null) {
			System.out.println("临时文件 " + file + " 创建成功。");
		}
	}

	private static File generateTempFile(String prefix, String suffix) {
		File result = null;
		try {
			result = File.createTempFile(prefix, suffix);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (result == null) {
			int rand = (int) (Math.random() * 0xFFFFFFFF);
			result = new File(prefix + String.format("_%X", rand) + suffix);
		}
		return result;

	}
}
